#include "widget.h"
#include "ui_widget.h"
#include <QMenu>
#include <QAction>
#include <QFileDialog>
#include "qss.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //在构造函数中创建多级菜单
    QMenu *fileMenuItems = new QMenu;

    //菜单添加ICON
    fileMenuItems->setIcon(QIcon(":/resources/file.png"));
    fileMenuItems->setTitle("文件");
    fileMenuItems->setStyleSheet(QString::fromStdString(menuItemQss));

    QList<QAction*> acList;

    //给action添加图像
    QAction *openFileAC = new QAction(QIcon(":/resources/file.png"), "打开文件", this);
    openFileAC->setShortcut(QKeySequence("Ctrl+8"));

    QAction *openFloderAC = new QAction("打开文件夹",this);
    QAction *openUrlA = new QAction("打开URL",this);

    //多级子菜单
    acList << openFileAC << openFloderAC << openUrlA;
    fileMenuItems->addActions(acList);

    QMenu *pMenu = new QMenu;   //主菜单
    pMenu->addMenu(fileMenuItems);

    QAction *play = new QAction(QIcon(":/resources/play.png"), "播放", this);
    QAction *tools = new QAction(QIcon(":/resources/tools.png"), "播放",this);
    pMenu->addAction(play);
    pMenu->addAction(tools);

    // 添加分隔符
    pMenu->addSeparator();

    QMenu *setMenuItems = new QMenu;
    setMenuItems->setTitle("设置");
    setMenuItems->setIcon(QIcon(":/resources/set.png"));
    QList<QAction*> setList;

    QAction *sysSetAc = new QAction("系统设置",this);
    QAction *playSetAc = new QAction("播放设置",this);
    QAction *zimuSetAc = new QAction("字幕设置",this);
    setList << sysSetAc << playSetAc << zimuSetAc;
    setMenuItems->addActions(setList);
    setMenuItems->setStyleSheet(QString::fromStdString(menuItemQss));
    pMenu->addMenu(setMenuItems);

     pMenu->addSeparator();

    QAction *exitAc = new QAction(QIcon(":/resources/exit.png"), "退出", this);
     pMenu->addAction(exitAc);

    ui->pushButton->setMenu(pMenu);
     connect(openFileAC, &QAction::triggered, [=]{
        QString fileName = QFileDialog::getOpenFileName(this, "请选择视频文件", "D:/", "视频(*.mp4 *.flv);;");

        if(fileName.isEmpty()){
            return;
        }
    });

        ui->pushButton->setText("QW影音");
    ui->pushButton->setFixedSize(100,32);
     ui->pushButton->setStyleSheet(QString::fromStdString(button_qss));
    pMenu->setStyleSheet(QString::fromStdString(menuQss));

}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{

}
